﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using Chefbook.DataObjects;
using NUnit.Framework;
using Rhino.Mocks;
using Chefbook.DataAccessLayer;
using Chefbook.UserActions;

namespace UnitTests.UserActionsTests
{
    [TestFixture]
    public class SaveRecipeActionFixture
    {
        private MockRepository mocks;
        private IUserAction action;
        private Category category;
        private Recipe recipe;
        private Ingredient ingredient;
        private ChefbookEntities db;
        

        [SetUp]
        public void Init()
        {
            mocks = new MockRepository();
            db = new ChefbookEntities();

            category = new Category();

            recipe = new Recipe();
            recipe.Description = "My Old Description";
            recipe.CookTime = TimeSpan.FromMinutes(35);
            ingredient = new Ingredient();
            recipe.AddIngredient(ingredient);
            ingredient.Name = "Teh Beef";

            Assert.AreEqual("My Old Description", recipe.Description);
            Assert.AreEqual(TimeSpan.FromMinutes(35), recipe.CookTime);
            Assert.Contains(ingredient, recipe.Ingredients.ToList());
            Assert.AreEqual("Teh Beef", ingredient.Name);
            Assert.AreEqual(1, recipe.Ingredients.Count);
            Assert.Contains(category, recipe.Categories);
            Assert.Contains(recipe, category.DirectRecipes);

            action = new SaveRecipeAction(recipe) { DatabaseConnector = db };
        }

        [Test]
        public void DoActionTest()
        {
            action.DoAction();
            Assert.Contains(category, recipe.Categories);
            Assert.Contains(recipe, category.DirectRecipes);
        }

        [Test]
        public void UndoActionThatIsNotUndoableTest()
        {
            UserActionTestsHelper.UndoActionThatIsNotUndoableTest(action);
        }

        [Test]
        public void UndoActionWithoutDoingTest()
        {
            UserActionTestsHelper.UndoActionWithoutDoingTest(action);
        }

        [Test]
        public void DoActionTwiceTest()
        {
            UserActionTestsHelper.DoActionTwiceTest(action);
        }

        [Test]
        public void ActionNameTest()
        {
            Assert.AreEqual(string.Format("Save Recipe '{0}'", recipe), action.ToString());
        }
    }
}
